package win.bigwhale.sudoku.controller;

import java.util.ArrayList;

import win.bigwhale.sudoku.GameScene;
import win.bigwhale.sudoku.HomeScene;
import win.bigwhale.sudoku.StartGame;
import win.bigwhale.sudoku.game.Sudoku;
import win.bigwhale.sudoku.view.ChooseGame;

public class GameController implements GameControlInterface {
	private static GameController gameController = null;
	private ArrayList<GameControlInterface> paneList = null;

	private GameController() {
		paneList = new ArrayList<GameControlInterface>();
	}

	private static synchronized void init() {
		if (gameController == null) {
			gameController = new GameController();
		}
	}

	public static synchronized GameController getGameController() {
		if (gameController == null) {
			init();;
		}
		return gameController;
	}

	public void addPane(GameControlInterface pane) {
		paneList.add(pane);
	}

	@Override
	public void startGame(Sudoku sudoku) {
		StartGame.getPrimaryStage().setScene(GameScene.getGameScene());
		ChooseGame.getChooseGame().close();

		for (GameControlInterface pane : paneList) {
			pane.startGame(sudoku);
		}
	}

	@Override
	public void pauseGame() {
		for (GameControlInterface pane : paneList) {
			pane.pauseGame();
		}
	}

	@Override
	public void resumeGame() {
		for (GameControlInterface pane : paneList) {
			pane.resumeGame();
		}
	}

	@Override
	public void restartGame() {
		for (GameControlInterface pane : paneList) {
			pane.restartGame();
		}
	}

	@Override
	public void endGame() {
		StartGame.getPrimaryStage().setScene(HomeScene.getHomeScene());
		for (GameControlInterface pane : paneList) {
			pane.endGame();
		}
	}

	@Override
	public void completeGame() {
		for (GameControlInterface pane : paneList) {
			pane.completeGame();
		}
	}
}
